package util;

import org.apache.commons.lang3.StringUtils;

import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Util {

    public static boolean isSameMethod(String methodA, String methodB) {
        return StringUtils.equals(getMd5Str(methodA), getMd5Str(methodB));
    }

    public static String getMd5Str(String str) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(ByteBuffer.wrap(str.getBytes(StandardCharsets.UTF_8)));
            return String.format("%032x", new BigInteger(1, messageDigest.digest()));
        } catch (NoSuchAlgorithmException e) {
            System.out.println("转换MD5出错");
        }
        return StringUtils.EMPTY;
    }
}
